<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <div id="app">
         <input type="text" v-model="val">
         {{obj.name}}
         <button @click="handle">还真研发？</button>
    </div>
    <script src='https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js'></script>
    <script>
        const vm = new Vue({
            el:"#app",
            data:{
                val:"",
                //侦听对象
                obj:{
                    name:"多喝热水",
                    sex:"男",
                    hobby:"和妹妹一起玩"
                }
            },
            methods:{
                handle(){
                    // this.$watch("val",(newval,oldval)=>{
                    //     console.log(newval);
                    //     console.log(oldval);
                    // })
                    //深度侦听
                    // this.$watch("obj",{
                    //     deep:true,
                    //     handler(newval){
                    //         console.log('deep',newval)
                    //     }
                    // })
                }
            },
            watch:{
            //    val(newval,oldval){
            //        console.log(newval);
            //        console.log(oldval)
            //    },
               obj:{
                //开启深度侦听
                 deep:true,
                 handler(newval,oldval){
                     //指针都是相同的
                     console.log(newval);
                 },
                 //立刻进行回调
                 immediate:true
               }
            //侦听对象中的某一个属性
            //  "obj.hobby"(newval,oldval){
            //       console.log(newval);
            //       console.log(oldval)
            //  }
            }
        })
    </script>
</body>
</html>